/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.openbrew.openbrewrf;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import org.eclipse.persistence.annotations.CascadeOnDelete;

/**
 *
 * @author dchapman
 */
@Entity
@Table(name = "RecipeSalts")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "RecipeSalts.findAll", query = "SELECT r FROM RecipeSalts r"),
    @NamedQuery(name = "RecipeSalts.findByRecipeSaltID", query = "SELECT r FROM RecipeSalts r WHERE r.recipeSaltID = :recipeSaltID"),
    @NamedQuery(name = "RecipeSalts.findByRecipeSaltDesc", query = "SELECT r FROM RecipeSalts r WHERE r.recipeSaltDesc = :recipeSaltDesc")})
public class RecipeSalts implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "recipeSaltID")
    private Integer recipeSaltID;
    @Basic(optional = false)
    @NotNull
    @Size(min = 0, max = 50)
    @Column(name = "recipeSaltDesc")
    private String recipeSaltDesc;
    @JoinColumn(name = "styleProfile", referencedColumnName = "profileID", nullable=true)
    @ManyToOne(optional = true)
    private StyleWaterProfiles profileID;
    @OneToMany(cascade=CascadeType.ALL, orphanRemoval = true)
    @CascadeOnDelete
    @JoinTable(
        name="JTRecipeToSelectedSalts",
        joinColumns={ @JoinColumn(name="recipeSaltID", referencedColumnName="recipeSaltID")},
        inverseJoinColumns={ @JoinColumn(name="selectedSaltID", referencedColumnName="selectedSaltID", unique=true)}
    )
    private List<SelectedSalt> selectedSaltCollection;
    @OneToMany(mappedBy = "recipeSaltID")
    private Collection<Recipes> recipesCollection;

    public RecipeSalts() {
    }

    public RecipeSalts(Integer recipeSaltID) {
        this.recipeSaltID = recipeSaltID;
    }

    public RecipeSalts(Integer recipeSaltID, String recipeSaltDesc) {
        this.recipeSaltID = recipeSaltID;
        this.recipeSaltDesc = recipeSaltDesc;
    }

    public Integer getRecipeSaltID() {
        return recipeSaltID;
    }

    public void setRecipeSaltID(Integer recipeSaltID) {
        this.recipeSaltID = recipeSaltID;
    }

    public String getRecipeSaltDesc() {
        return recipeSaltDesc;
    }

    public void setRecipeSaltDesc(String recipeSaltDesc) {
        this.recipeSaltDesc = recipeSaltDesc;
    }

    public StyleWaterProfiles getProfileID() {
        return profileID;
    }

    public void setProfileID(StyleWaterProfiles profileID) {
        if(profileID != null && profileID.getProfileID()!= null){
            this.profileID = profileID;
        }
    }

    public List<SelectedSalt> getSelectedSaltCollection() {
        return selectedSaltCollection;
    }

    public void setSelectedSaltCollection(List<SelectedSalt> selectedSaltCollection) {
        this.selectedSaltCollection = selectedSaltCollection;
    }

    @XmlTransient
    public Collection<Recipes> getRecipesCollection() {
        return recipesCollection;
    }

    public void setRecipesCollection(Collection<Recipes> recipesCollection) {
        this.recipesCollection = recipesCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (recipeSaltID != null ? recipeSaltID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof RecipeSalts)) {
            return false;
        }
        RecipeSalts other = (RecipeSalts) object;
        if ((this.recipeSaltID == null && other.recipeSaltID != null) || (this.recipeSaltID != null && !this.recipeSaltID.equals(other.recipeSaltID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.openbrew.openbrewrf.RecipeSalts[ recipeSaltID=" + recipeSaltID + " ]";
    }
    
}
